﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestMethodExtension : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- Method extension ---");
        }

        public void doTest()
        {
            int value = 3;

            Console.WriteLine("Square {0} = {1}", value, value.square());

            NeedExtClass needExtObj = new NeedExtClass(5);

            Console.WriteLine("5 * 3 = {0}", needExtObj.x3());
        }
    }

    public static class IntegerExtension
    {
        public static int square(this int myInt)
        {
            return myInt * myInt;
        }
    }

    public static class NeedExtExtension
    {
        public static int x3(this NeedExtClass aExtClass) 
        {
            return aExtClass.getValue() * 3;
        }
    }

    class NeedExtClass
    {
        private int mValue;

        public NeedExtClass(int aValue)
        {
            this.mValue = aValue;
        }

        public int getValue()
        {
            return mValue;
        }

        public int x2()
        {
            return mValue * 2;
        }


    }
}
